home *** CD-ROM | disk | FTP | other *** search
- /*
- File: PlfmFile.h
-
- Contains: Platform-file wrapper class
-
- Owned by: Vincent Lo
-
- Copyright: © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <5> 6/27/96 jpa T10012: Changed kODMagicFileTypeChar to
- avoid conflict w/developer
- <4> 5/31/96 jpa T10012: Added IsOpenDocDocument.
- <3> 5/24/96 jpa 1.1MRD: pragma internal.
- <2> 5/8/96 NP 1282265: saving as stationery looks like
- document
-
- To Do:
- In Progress:
-
- */
-
- #ifndef _PLFMFILE_
- #define _PLFMFILE_
-
- #ifndef _ODTYPES_
- #include "ODTypes.h"
- #endif
-
- #ifndef _PLFMDEF_
- #include "PlfmDef.h"
- #endif
-
- #ifndef _ODMEMORY_
- #include "ODMemory.h"
- #endif
-
- #ifndef _ITEXT_
- #include "IText.h" /* For ODScriptCode type */
- #endif
-
- #ifndef __FILES__
- #include <Files.h>
- #endif
-
- //==============================================================================
- // Theory of Operation
- //==============================================================================
-
- //==============================================================================
- // Constants
- //==============================================================================
-
- const unsigned char kODMagicFileTypeChar = 0xCD;
- // Magic 1st char of filetype ('Õ' or option-n, shift-o)
-
- const ODSShort kODNoFileRefNum = 0;
- const ODSShort kODMaxFileNameSize = 31;
- const ODULong kODNoFileID = 0;
-
- //==============================================================================
- // Scalar Types
- //==============================================================================
-
- typedef FSSpec ODFileSpec;
- typedef short ODFileRefNum;
- typedef ODSByte ODFilePermission;
-
- typedef ODFileRefNum *ODFileRefNumPtr;
-
- enum PFUniquifyAction { kSpecifyNewNameOnly, kRenameInPlace };
-
- const ODBoolean kODTryCurrentName = kODFalse;
- const ODBoolean kODForceNewName = kODTrue;
-
- const ODSShort kODNoResourceID = 0;
-
- //==============================================================================
- // Classes defined in this interface
- //==============================================================================
-
- class PlatformFile;
- class CWithActiveResources; // private class
-
-
- //==============================================================================
- // PlatformFile
- //==============================================================================
-
- #ifdef PRAGMA_INTERNAL_SUPPORTED
- #pragma internal on
- #endif
-
- class PlatformFile
- {
- public:
-
- PlatformFile();
- ~PlatformFile();
-
- // Methods you can call when the file is not open:
- // pointing the PlatformFile at a physical file and setting default opening permissions
- // Specify() can only be called once on the object. If it is being called more than once,
- // the behavior is unpredictable. If you want to work with a different file,
- // you need to delete the current object and create a new one.
- ODNVMethod void Specify(const ODFileSpec* fileSpec);
- ODNVMethod void SpecifyFromFile(PlatformFile* file);
- ODNVMethod void SetAsciiName(const char* name);
- inline void SetPermission(ODFilePermission filePermission);
- // create/open/delete the file
- inline void SetFileRefNum( ODFileRefNum );
- ODNVMethod void Create(ODOSType creator, ODOSType fileType, ODScriptCode scriptCode);
- ODNVMethod void Open();
- ODNVMethod void Delete();
-
- // These are optional and simply optimize multiple resource calls
- ODNVMethod void OpenResFile();
- ODNVMethod void CloseResFile();
- // create the resource fork (only to be used after Create).
- ODNVMethod void CreateResFile();
-
- // Methods you can call anytime after calling Specify or SetAsciiName
- ODNVMethod ODBoolean IsEqualTo(PlatformFile* file);
- ODNVMethod ODBoolean IsLocked();
- ODNVMethod void Lock();
- ODNVMethod void Unlock();
- ODNVMethod ODBoolean IsStationery();
- ODNVMethod void SetStationery(ODBoolean isStationery);
- ODNVMethod void SetCustomIcon(ODBoolean hasCustomIcon);
- ODNVMethod ODBoolean HasCustomIcon();
- ODNVMethod ODBoolean IsDirectory();
- ODNVMethod void SetCustomIconFamily(ODIconFamily icons);
- ODNVMethod ODIconFamily GetCustomIconFamily();
- ODNVMethod ODBoolean Exists();
- ODNVMethod ODUShort GetFInfoFlags();
- ODNVMethod void SetFinderFlag(ODUShort flag);
- ODNVMethod void UnsetFinderFlag(ODUShort flag);
-
- ODNVMethod ODBoolean IsOpenDocDocument( );
- static ODBoolean IsOpenDocDocument( OSType type, OSType creator );
-
-
- // Get & set the Desktop DB comment field
- ODNVMethod ODIText* GetComments(ODIText* comments = kODNULL);
- ODNVMethod void SetComments(ODIText* comments);
-
- ODNVMethod void FlushVolume();
-
- ODNVMethod ODName* GetName();
- ODNVMethod void GetAsciiName(char* name,ODULong maxLength);
- inline ODULong GetAsciiNameLength();
- ODNVMethod ODOSType GetPlatformCreator(); // Macintosh specific
- ODNVMethod void SetPlatformCreator(ODOSType fileType); // Macintosh specific
- ODNVMethod ODOSType GetPlatformType(); // Macintosh specific
- ODNVMethod void SetPlatformType(ODOSType fileType); // Macintosh specific
- ODNVMethod ODContainerType GetContainerType();
- ODNVMethod void SetContainerType(ODContainerType containerType);
- ODNVMethod ODPtr ReadResourcePtr(ODPlatformType resType, ODSShort resID, ODULong* size); // Mac
- ODNVMethod void WriteResourcePtr(ODPlatformType resType, ODSShort resID,
- const void *resPtr, ODULong size); // Mac
- ODNVMethod void DeleteResource(ODPlatformType resType, ODSShort resID); // Mac
- inline ODFileSpec& GetFileSpec();
- ODNVMethod void MoveRename( ODFileSpec* newSpec, ODBoolean isDuplicate ) ;
- ODNVMethod void Move( ODSLong targetParID ) ;
- ODNVMethod void UniquifyName( ODSShort uniquifyingStringID,
- StringHandle uniquifyingString,
- ODSShort uniquifyingNumberID,
- StringHandle uniquifyingNumberString,
- short copyCount,
- PFUniquifyAction action,
- ODBoolean forceNewName);
- ODNVMethod void MoveToTrash() ;
- ODNVMethod void Rename( Str63 name ) ;
- ODNVMethod ODTime GetFileModDate();
- ODNVMethod void SetFileModDate(ODTime date);
- ODNVMethod ODTime GetFileCreationDate();
- ODNVMethod void SetFileCreationDate(ODTime date);
- ODNVMethod ODULong GetAllocationBlockSize();
- ODNVMethod void BumpFolderModDate();
-
- ODNVMethod ODBoolean IsInTrash( );
-
- // Methods you must call while the file is open
- ODNVMethod void Close();
-
- ODNVMethod void SetFilePos(ODSShort posMode, ODSLong posOff);
- ODNVMethod ODSLong GetFilePos();
-
- ODNVMethod void Read(void* buffer, ODSLong* count);
- ODNVMethod void Write(const void* buffer, ODSLong* count);
-
- ODNVMethod ODSLong GetEndOfFile();
- ODNVMethod void SetEndOfFile(ODSLong length);
-
- inline ODFileRefNum GetFileRefNum();
-
- ODNVMethod void CopyFrom( PlatformFile* src );
-
-
- private:
- /* Constants to specify the file fork GetLocalPaths should match */
- enum
- {
- kODDataFork = 0,
- kODResourceFork = 1
- };
- typedef short ODForkType;
-
- ODNVMethod void GetFileID( );
- ODNVMethod void UpdateSpecFromID( );
- ODNVMethod ODBoolean ActivateResourceFile( ODBoolean &needToCloseResFile );
-
- ODNVMethod ODFileRefNum GetFirstLocalPath( ODForkType fork );
-
-
- public:
- ODNVMethod ODError GetLocalPaths(
- ODForkType fork,
- ODULong *refNumCount,
- ODFileRefNumPtr *refNums);
-
- /* Determine if local access paths to a file fork are open.
- The GetLocalPaths function looks through the FCB list to see if
- the fork of the file specified by spec and fork is open by the
- local File Manager (you should use PBGetCatInfo and check
- ioFlAttrib if you need to see if *anyone* has the file fork open
- *anywhere*). If the result is noErr, GetLocalPaths returns a
- count and a pointer to an array of file refNums (if count is
- not zero) of local access paths to the specified file fork.
-
- spec input: An FSSpec record specifying the file.
- fork input: Specifies the file fork - either kDataFork
- or kResourceFork.
- refNumCount output: The number of local access paths found.
- refNums output: If not NULL, a pointer to an array of
- file refNums - the number of which is
- specified by refNumCount. The caller is
- responsible for disposing of this pointer.
- */
-
- private:
-
- ODFileSpec fFileSpec;
- ODSShort fDataRefNum;
- ODFilePermission fPermission;
- ODContainerType fContainerType;
- ODOSType fCreator;
- ODOSType fFileType;
- ODScriptCode fScriptTag;
- ODULong fFileID;
- ODULong fVolModDate;
- ODULong fTimeLastChecked;
- ODFileRefNum fResRefNum;
- ODULong fResOpenStack;
- ODBoolean fNeedToClose;
-
- friend class CWithActiveResources;
- };
-
-
- //------------------------------------------------------------------------------
- // Inline method bodies
- //------------------------------------------------------------------------------
-
-
- inline ODULong PlatformFile::GetAsciiNameLength()
- {
- return fFileSpec.name[0];
- }
-
- void PlatformFile::SetPermission(ODFilePermission permission)
- {
- fPermission = permission;
- }
-
- inline ODFileSpec& PlatformFile::GetFileSpec()
- {
- return fFileSpec;
- }
-
- inline ODFileRefNum PlatformFile::GetFileRefNum()
- {
- return fDataRefNum;
- }
-
- inline void PlatformFile::SetFileRefNum( ODFileRefNum refNum )
- {
- fDataRefNum = refNum;
- }
-
-
- #ifdef PRAGMA_INTERNAL_SUPPORTED
- #pragma internal reset
- #endif
-
- #endif // _PLFMFILE_
-